package com.droidnova.android.games.vortex;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class VortexView extends GLSurfaceView {
	private final static String TAG = VortexView.class.getSimpleName();
	private VortexRender  vortexRender;
	private float _x = 0.0f;
	private float _y = 0.0f;

	public VortexView(Context context) {
		super(context);
		vortexRender = new VortexRender();
		setRenderer(vortexRender);
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean onTouchEvent(final MotionEvent event) {
		// TODO Auto-generated method stub
		if(event.getAction()==MotionEvent.ACTION_DOWN){
			_x = event.getX();
			_y = event.getY();
		}
		if(event.getAction()==MotionEvent.ACTION_MOVE){
			final float xdiff = (_x - event.getX());
			final float ydiff = (_y - event.getY());
			queueEvent(new Runnable(){

				@Override
				public void run() {
					// TODO Auto-generated method stub
					vortexRender.setColor(event.getX()/getWidth(), event.getY()/getHeight(), 10.0f);
					vortexRender.setXAngle(vortexRender.getXAngle() + ydiff);
					vortexRender.setYAngle(vortexRender.getYAngle() + xdiff);
				}});
			_x = event.getX();
			_y = event.getY();
		}
		
		return true;
	} 

	
}
